package expansion.beanFactoryPostProcessor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor, Ordered {
    // Spring IoC 容器允许 BeanFactoryPostProcessor 在容器实际实例化任何其它的 bean 之前读取配置元数据，并有可能修改它。
    // 同时 BeanFactoryPostProcessor 的回调比 BeanPostProcessor 要早
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        System.out.println("MyBeanFactoryPostProcessor...postProcessBeanFactory...");
        int count = beanFactory.getBeanDefinitionCount();
        String[] names = beanFactory.getBeanDefinitionNames();
        System.out.println("当前BeanFactory中有" + count + " 个Bean");
        System.out.println(Arrays.asList(names));
    }

    /**
     * 优先级
     *
     * @return
     */
    @Override
    public int getOrder() {
        return 0;
    }
}